package com.learning.springboot.service;

import com.learning.springboot.Thymeleaf.entity.Person;
import com.learning.springboot.springdataJpa.PersonRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by td on 2017/9/30.
 */
@Service
public class DemoServiceImpl implements DemoService {
    @Autowired
    private PersonRepository personRepository;


    @Override
    @Transactional(noRollbackFor = {IllegalArgumentException.class})
    public Person savePersonRollback() {

        Person person = new Person("wanger",20);

        Person person1 = personRepository.save(person);

        if (person.getName().equals("wanger")) {

            throw new IllegalArgumentException("wanger 存在");
        }
        return person1;
    }
}
